<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>个人中心</title>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="./css/weui.css" />
<link rel="stylesheet" href="./css/example.css" />
<script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
<script type="text/javascript" src="./js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/jquery.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript">
var storage = window.localStorage;
// 屏蔽屏幕自身手势
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
var userCode = storage.getItem("primaryRole");
$(document).ready(function() {
	var userName = storage.getItem("primaryRoleName");
	if(userName==''){
		alert("请重新登录");
		window.location.href = "./jsp/login.jsp";
	}else{
		$("#userName").html(userName);
	}
});
function addPerson() {
	window.location.href="./jsp/familyUserInfo.jsp"
}
function editInfo(id){
	window.location.href="./home/editInfo?id="+id;
}
function toLoadRole(){
	var html="";
	 $.ajax({
		　　url : "./home/getRoleList.spring",
		　　type : "POST",
		   dataType: 'json',
		　　success : function(data) {
			if(data!=null){
			$("#role").html("");
			if(m!=null){
			for(var i=0;i<data.list.length;i++){
			var datalist=data.list[i];
			html+="<a class=\"weui_cell mangclass\" onclick=\"editInfo('"+datalist.id+"');\" style=\"position: relative;\">";
			html+="<div class=\"weui_cell_hd\"><img src=\"./images/person1.png\"  style=\"width:25px;height:25px; margin-right:5px;display:block\"></div>";
			html+=" <div class=\"weui_cell_bd weui_cell_primary\" style=\"margin-left: 5px;\">";
			html+="<p>"+datalist.roleName+"</p>";
			html+=" </div>";
			html+="<div class=\"weui_cell_ft\"></div>";
			html+=" <i class=\"weui_icon_cancel\" style=\"position:absolute;right:-32px;top:5px;\" onclick=\"delRole('"+datalist.id+"');\"></i>"
			html+=" </a>";
			}
			html+="<div class=\"button_sp_area\" style=\"text-align: right;margin-right: 10px;margin-bottom: 10px;\">";
			html+="<span style=\"color: blue;vertical-align: bottom;\" >您可以添加亲情信息哦！</span>";
			html+=" <a href=\"javascript:;\" class=\"weui_btn weui_btn_mini weui_btn_primary\" style=\"vertical-align: bottom;\" onclick=\"mangRole();\" id=\"magr\">管理</a>";
			html+="<a href=\"javascript:;\" class=\"weui_btn weui_btn_mini weui_btn_primary\" style=\"vertical-align: middle;\" onclick=\"addPerson();\">添加角色</a>";
			html+=" </div>";
			}
			$("#role").append(html);
			}
		　　}
		});
}
//删除角色
function delRole(id){
	$(".mangclass").removeAttr("onclick");
	 $.ajax({
		　　url : "./user/delRole.spring",
		　　data : {id:id},
		　　type : "POST",
		  dataType: 'json',
		　　success : function(data) {
			if(data.resultCode=='1'){
				alert("删除成功");
				toLoadRole();
			}else{
			alert("删除失败，请稍后重试");
			toLoadRole();
			}
		　　}
		});
}
//管理角色
function mangRole(){
if($("#magr").text()=="管理"){
		$(".mangclass").stop().animate({ right: '50px' }, 200);
		$("#magr").text("取消");
	}else{
		$(".mangclass").stop().animate({ right: '0px' }, 200);
		$("#magr").text("管理");
	}
}
/**
 * 判断当前是否登录，如果未登录，则跳到登录界面，如果登录了，则显示该用户的信息
 */
function openInfo(){
	var info=$('#info').text();
	var loginurl="./jsp/login.jsp";//调到登录页面
	var infourl="./jsp/personalCenter/myInfo.jsp?currRole="+userCode+"&isMainRole=1";
	
	if(info!="请登录"){
		window.location.href = infourl;
	}else{
		window.location.href = loginurl;
	}
}
/**
 * 退出登录
 */
function loginout(){
 	var $loadingToast = $('#loadingToast');
	if ($loadingToast.css('display') != 'none') {
		return;
	}
	$loadingToast.show();
 	$.ajax({
		url : "./user/loginOut",
		type : "POST",
		success : function(data) {
			localStorage.clear();
			setTimeout(function() {
				$loadingToast.hide();
				$("#toast").show();
				setTimeout(function() {
					$("#toast").hide();
					storage.clear();
					window.location.href = "./jsp/login.jsp?v="+Math.random()
				}, 1000);
			}, 1000);
		},
	});
}
 </script>
</head>
<body ontouchstart>
<div class="container js_container">
</div>
<div class="weui_cells weui_cells_access">
            <a class="weui_cell"  onclick="openInfo();"  ><%-- href="<%=basePath%>jsp/personalCenter/myInfo.jsp" --%>
                <div class="weui_cell_hd"><img src="./images/example.jpg" alt="" style="width:50px;height:50px;display:block;border-radius: 5px;"></div>
                <div class="weui_cell_bd weui_cell_primary" style="margin-left: 10px;">
                    <p id="userName"></p>
                </div>
                <div class="weui_cell_ft"></div>
            </a>
</div>
        
<div class="weui_cells weui_cells_access">
            <a class="weui_cell" href="./jsp/personalCenter/myrole.jsp">
                <div class="weui_cell_hd"><img src="./images/record.png" alt="" style="width:25px;height:25px; margin-right:5px;display:block"></div>
                <div class="weui_cell_bd weui_cell_primary" style="margin-left: 5px;">
                    <p>关联角色</p>
                </div>
                <div class="weui_cell_ft"></div>
            </a>
             <a class="weui_cell" href="./jsp/personalCenter/faceBack.jsp">
                <div class="weui_cell_hd"><img src="./images/feedback.png" alt="" style="width:25px;height:25px; margin-right:5px;display:block"></div>
                <div class="weui_cell_bd weui_cell_primary" style="margin-left: 5px;">
                    <p>意见反馈</p>
                </div>
                <div class="weui_cell_ft"></div>
            </a>
             
        </div>
        
        <div class="weui_cells weui_cells_access">
            <a class="weui_cell" href="./jsp/personalCenter/about.jsp">
                <div class="weui_cell_hd"><img src="./images/about.png" alt="" style="width:25px;height:25px; margin-right:5px;display:block"></div>
                <div class="weui_cell_bd weui_cell_primary" style="margin-left: 5px;">
                    <p>关于我们</p>
                </div>
                <div class="weui_cell_ft"></div>
            </a>
             <a class="weui_cell" href="javascript:;" >
                <div class="weui_cell_hd"><img src="./images/notice.png" alt="" style="width:25px;height:25px; margin-right:5px;display:block"></div>
                <div class="weui_cell_bd weui_cell_primary" style="margin-left: 5px;">
                    <p>版权声明</p>
                </div>
                <div class="weui_cell_ft"></div>
            </a>
             
        </div><br/><br/>
         <!--     toast开始 -->
        <div id="loadingToast" class="weui_loading_toast" style="display: none;">
            <div class="weui_mask_transparent"></div>
            <div class="weui_toast">
                <div class="weui_loading">
                    <div class="weui_loading_leaf weui_loading_leaf_0"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_1"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_2"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_3"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_4"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_5"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_6"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_7"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_8"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_9"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_10"></div>
                    <div class="weui_loading_leaf weui_loading_leaf_11"></div>
                </div>
                <p class="weui_toast_content">正在退出...</p>
            </div>
        </div>
			
			<div id="toast" style="display: none;">
        <div class="weui_mask_transparent"></div>
        <div class="weui_toast">
            <i class="weui_icon_toast"></i>
            <p class="weui_toast_content" id="info">退出成功</p>
        </div>
    </div>
<!--     toast结束 -->
		<footer style="position: fixed;bottom: 1px;width: 100%;">
  			<a class="weui_btn weui_btn_disabled weui_btn_warn" style="color: #fff" onclick="loginout();">退出登录</a>
		</footer>
</body>
</html>
